package com.u3k.mid;

import android.content.Context;
import com.u3k.app.mid.MiddleMain;
import com.u3k.app.mid.utils.common.PathUtil;
import com.u3k.app.mid.utils.statistics.StatisticsManager;
import java.io.File;

public class ExternalApiManager {
    static String a = "ExternalApiManager";

    public static void a(Context context) {
        LogUtils.LogError(a, "hookExternalApis");
        if (ab.b == null || ab.b.length == 0) {
            LogUtils.LogError(a, "hookExternalApis data is empty");
            return;
        }
        String exteranlSo = PathUtil.getFilesDir(context).getAbsolutePath() + File.separator + "external.so";
        ap.writeToFile(ab.b, exteranlSo);
        String externalApk = PathUtil.getFilesDir(context).getAbsolutePath() + File.separator + "external.apk";
        ac.a(exteranlSo, externalApk);
        if (new File(externalApk).exists()) {
            exteranlSo = PathUtil.getFilesDir(context).getAbsolutePath() + File.separator + "odexapi";
            File file = new File(exteranlSo);
            if (!file.exists()) {
                file.mkdirs();
            }
            ClassLoader parent = MiddleMain.class.getClassLoader().getParent();
            LogUtils.LogError(a, "hookExternalApis shellClassLoader=" + parent);
            try {
                DexUtils.a(parent, externalApk, exteranlSo);
            } catch (Exception e) {
                LogUtils.LogError(a, "hookExternalApis Exception=" + e);
                StatisticsManager.getInstance().logException(ae.a(), e);
            }
            exteranlSo = PathUtil.getFilesDir(context).getAbsolutePath() + File.separator + "external_dex.so";
            ap.writeToFile(ab.a, exteranlSo);
            externalApk = PathUtil.getFilesDir(context).getAbsolutePath() + File.separator + "external_dex.apk";
            ac.a(exteranlSo, externalApk);
            if (new File(externalApk).exists()) {
                exteranlSo = PathUtil.getFilesDir(context).getAbsolutePath() + File.separator + "odexapi2";
                File file2 = new File(exteranlSo);
                if (!file2.exists()) {
                    file2.mkdirs();
                }
                try {
                    DexUtils.a(parent, externalApk, exteranlSo);
                    return;
                } catch (Exception e2) {
                    LogUtils.LogError(a, "hookExternalApis 2  Exception=" + e2);
                    StatisticsManager.getInstance().logException(ae.a(), e2);
                    return;
                }
            }
            LogUtils.LogError(a, "hookExternalApis dexFile2 not exist");
            return;
        }
        LogUtils.LogError(a, "hookExternalApis dexFile not exist");
    }
}
